//
//  GYSearchViewModel.m
//  GYDemo
//
//  Created by Mrzhang on 2018/4/11.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYSearchViewModel.h"
#import "Head.h"
@implementation GYSearchViewModel
-(NSMutableArray *)buyArr
{
    if (!_buyArr) {
        _buyArr=[[NSMutableArray alloc] init];

    }
    return _buyArr;
}

-(NSMutableArray *)saleArr
{
    if (!_saleArr) {
        _saleArr=[[NSMutableArray alloc] init];
    }
    return _saleArr;
}
-(instancetype)init
{
    if (self = [super init]) {
        //添加接口特殊处理
        [[InterfaceManager shareInterface].specialInterfaces addObject:@"findBuy"];
        [[InterfaceManager shareInterface].specialInterfaces addObject:@"findSupply"];
    }
    return self;
}
-(void)requestBuyData:(NSMutableDictionary *)para
{
    @WeakSelf;
    NSString *interface = @"findBuy";
    NSString *page = para[@"page"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSDictionary *data = infoModel.data;
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSArray *datalist = data[@"datalist"];
            
            if ([datalist count]<10) {
                selfp.BuyCanAddMore=NO;
            }else
            {
                selfp.BuyCanAddMore=YES;
            }
            if ([datalist isKindOfClass:[NSArray class]]) {
                NSMutableArray *arr;
                if ([page isEqualToString:@"1"]) {
                    arr = [NSMutableArray new];
                }else{
                    arr = _buyArr;
                }
                
                for (NSDictionary *dic in datalist) {
                    GYHomeBuyProductInfoModel *model = [GYHomeBuyProductInfoModel yy_modelWithJSON:dic];
                    [arr addObject:model];
                }
                [selfp setBuyArr:arr];

            }
        }else
        {
            NSMutableArray *arr=[NSMutableArray new];
            [selfp setBuyArr:arr];
        }
    }];
}
-(void)requestSaleData:(NSMutableDictionary *)para
{
    @WeakSelf;
    NSString *interface = @"findSupply";
    NSString *page = para[@"page"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSDictionary *data = infoModel.data;
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSArray *datalist = data[@"datalist"];
            
            if ([datalist count]<10) {
                selfp.SaleCanAddMore=NO;
            }else
            {
                selfp.SaleCanAddMore=YES;
            }
            if ([datalist isKindOfClass:[NSArray class]]) {
                NSMutableArray *arr;
                if ([page isEqualToString:@"1"]) {
                    arr = [NSMutableArray new];
                }else{
                    arr = _saleArr;
                }
                for (NSDictionary *dic in datalist) {
                    GYMineLikeProductInfoModel *model = [GYMineLikeProductInfoModel yy_modelWithJSON:dic];
                    [arr addObject:model];
                }
                [selfp setSaleArr:arr];

            }
        }else
        {
            NSMutableArray *arr=[NSMutableArray new];
            [selfp setSaleArr:arr];
        }
    }];
}
@end
